package user

import (
	"time"

	"gitcode.com/G-YT/baoyou/server/global"
	"gitcode.com/G-YT/baoyou/server/model/manager"
	"gitcode.com/G-YT/baoyou/server/model/system"
	"gitcode.com/G-YT/baoyou/server/plugin/geo/model"
	"github.com/google/uuid"
)

type Login interface {
	GetName() string
	GetUUID() uuid.UUID
	GetUserId() uint
	GetAuthorityId() uint
	GetUserInfo() any
}

var _ Login = new(User)

type User struct {
	global.GvaModel
	UUID             uuid.UUID             `json:"uuid" gorm:"index;column:uuid;comment:用户UUID"`
	ServiceStationID uint                  `json:"serviceStationID" form:"serviceStationID" gorm:"column:service_station_id;comment:服务站id"`
	HealthManagerID  uint                  `json:"healthManagerID" form:"healthManagerID" gorm:"column:health_manager_id;comment:健管师id"`
	Phone            string                `json:"phone" gorm:"column:phone;comment:用户手机号"`
	OpenID           string                `json:"openID" gorm:"column:open_id;comment:微信OpenID"`
	Password         string                `json:"password" gorm:"column:password;comment:登录密码"`
	Name             string                `json:"name" form:"name" gorm:"column:name;comment:名称"`
	Cm               float64               `json:"cm" gorm:"column:cm;comment:身高(cm)"`
	Kg               float64               `json:"kg" gorm:"column:kg;comment:体重(kg)"`
	Waistline        float64               `json:"waistline" gorm:"column:waistline;comment:腰围(cm)"`
	Hipline          float64               `json:"hipline" gorm:"column:hipline;comment:臀围(cm)"`
	Avatar           string                `json:"avatar" gorm:"column:avatar;default:https://image.cushdylm.com/app/default_avatar.jpg;comment:用户头像"`
	Types            uint                  `json:"types" gorm:"column:types;default:1;comment:用户类型 1用户 2会员 3过期会员"`
	Sex              uint                  `json:"sex" gorm:"column:sex;default:1;comment:性别 1男 2女"`
	Birthday         time.Time             `json:"birthday" gorm:"column:birthday;comment:生日"`
	Province         uint                  `json:"province" gorm:"column:province;comment:省"`
	City             uint                  `json:"city" gorm:"column:city;comment:市"`
	Area             uint                  `json:"area" gorm:"column:area;comment:区/县;"`
	Addr             string                `json:"addr" gorm:"column:addr;comment:详细地址;"`
	Status           uint                  `json:"status" form:"status"  gorm:"column:status;comment:状态 正常1 冻结0;default:1;"`
	Points           uint                  `json:"points" form:"points"  gorm:"column:points;comment:积分;default:0;"`
	Contact          string                `json:"contact" gorm:"column:contact;comment:紧急联系人"`
	ContactPhone     string                `json:"contact_phone" gorm:"column:contact_phone;comment:紧急联系电话"`
	EfficacyTagIDs   string                `json:"e_ids" gorm:"column:efficacy_tag_ids;comment:功效ID集合"`
	LastLoginAt      time.Time             `json:"lastLoginAt" gorm:"column:last_login_at;comment:最后登录时间"`
	LastLoginType    string                `json:"lastLoginType" gorm:"column:last_login_type;comment:最后登录类型"`
	HealthManager    manager.HealthManager `json:"healthManager" gorm:"->;foreignKey:HealthManagerID;references:HmID;"` //健管师相关
	ProvinceInfo     model.GeoProvince     `json:"provinceInfo" gorm:"->;foreignKey:Code;references:Province;"`         // 省关联
	CityInfo         model.GeoCity         `json:"cityInfo" gorm:"->;foreignKey:Code;references:City;"`                 // 市关联
	AreaInfo         model.GeoArea         `json:"areaInfo" gorm:"->;foreignKey:Code;references:Area;"`                 // 区关联
	ServiceStation   system.SysUser        `json:"serviceStation" gorm:"->;foreignKey:ServiceStationID;references:ID;"`
}

func (User) TableName() string {
	return "by_user"
}

func (s *User) GetName() string {
	return s.Name
}

func (s *User) GetUUID() uuid.UUID {
	return s.UUID
}

func (s *User) GetUserId() uint {
	return s.ID
}

func (s *User) GetAuthorityId() uint { return 6666 }

func (s *User) GetUserInfo() any {
	return *s
}
